<style lang="scss">
.z-com-grid-view {
}
</style>

<template>
  <div class="z-com-grid-view">
    <component is="z-com-grid"
               v-bind="cprops"
    ></component>
<!--    {{cprops}}-->
  </div>
</template>

<script>
import {defineCurdView} from "../../ext/view";

export default defineCurdView({
  name: "ZComGridView",
  watch: {
    items() {
      // console.log('sdsds')
      this.reloadItems()
    }
  },

  data() {
    return {
      exportScope: {},
      cprops:{
        ...this.ctxProps,
        list: []
      },
    }
  },
  mounted() {
    this.reloadItems()
  },
  methods: {
    reloadItems() {
      let self = this
      self.exportScope = {
        viewName: 'z-com-mode',
        columns: this.columns,
        columnDefMap: this.columnDefMap,
        getColumnItem(item) {
          let ret = {}
          this.columns.forEach(column => {
            if (item.hasOwnProperty(column.prop)) {
              ret[column.prop] = item[column.prop]
            }
          })
          // console.log(ret)
          return ret
        },
        getColumnByKey(key) {
          let ret = this.columns.find(v => v.prop === key)
          return ret
        }
      }
      self.cprops.list = this.items.map(item => {
        return {
          ...item,
        }
      })
    },
  }
})
</script>

